package bacnetnetwork1;

import com.serotonin.bacnet4j.LocalDevice;
import com.serotonin.bacnet4j.exception.BACnetServiceException;
import com.serotonin.bacnet4j.obj.BACnetObject;
import com.serotonin.bacnet4j.type.enumerated.EngineeringUnits;
import com.serotonin.bacnet4j.type.enumerated.ObjectType;
import com.serotonin.bacnet4j.type.enumerated.PropertyIdentifier;
import com.serotonin.bacnet4j.type.primitive.*;
import com.serotonin.bacnet4j.type.primitive.Boolean;


public class ElectricRadiator extends LocalDevice {
    
    public ElectricRadiator(int ID, String networkAddress, String deviceAddress, int port, String name, EngineeringUnits units) throws Exception {
        // Create Sensor as LocalDevice
        super(ID, networkAddress,deviceAddress);        
        this.getConfiguration().setProperty(PropertyIdentifier.objectName,
                new CharacterString(name));
        this.setPort(port);

        BACnetObject mso1 = new BACnetObject(this,
                this.getNextInstanceObjectIdentifier(ObjectType.multiStateOutput));
        mso1.setProperty(PropertyIdentifier.objectName, new CharacterString("Actuator output"));
        //mso1.setProperty(PropertyIdentifier.outputUnits, units);
        mso1.setProperty(PropertyIdentifier.outOfService, new Boolean(false));
        mso1.setProperty(PropertyIdentifier.numberOfStates, new UnsignedInteger(41));
        int j=1;
        for (float i=2000;i > -2100;i=i-100) {
            mso1.setProperty(PropertyIdentifier.stateText,j,new CharacterString((new Real(i)).toString()));
            j++;
        }
        this.addObject(mso1);
        
        //Start device
        this.initialize();       
        
    }    
    
    public void setOutOfService(boolean givenValue) throws BACnetServiceException {
        BACnetObject ai=this.getObject("Actuator output"); 
        ai.setProperty(PropertyIdentifier.outOfService, new Boolean(givenValue));
    }
    
    public void setActuatorOutput(double givenValue) throws BACnetServiceException {
        BACnetObject ai=this.getObject("Actuator output"); 
        ai.setProperty(PropertyIdentifier.presentValue, new Real((float)givenValue));
    }
        
}
